package team.seekers.hula.island.island.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.enums.IslandTypeEnum;
import team.seekers.hula.island.island.entity.vo.IslandListVO;
import team.seekers.hula.island.islandUser.entity.vo.IslandUserListVO;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 浪屿表
 * @author ekin
 * @Description GOOD
 * @mood happy
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="Island对象", description="岛屿表")
@TableName(value = "island")
public class IslandDO implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.ID_WORKER_STR)
    private String id;

    @ApiModelProperty(value = "浪屿主理人id")
    private String userId;

    @ApiModelProperty(value = "浪屿主理团队id")
    private String teamId;

    @ApiModelProperty(value = "浪屿的名字")
    private String name;

    @ApiModelProperty(value = "浪屿的简介")
    private String description;

    @ApiModelProperty(value = "浪屿的背景图")
    private String background;

    @ApiModelProperty(value = "浪屿的主题色")
    private String theme;

    @ApiModelProperty(value = "浪屿的全屏背景图")
    private String fullBackground;

    @ApiModelProperty(value = "浪屿的介绍")
    private String introduction;

    @ApiModelProperty(value = "浪屿绑定的知桨id集合")
    private String courseIds;

    @ApiModelProperty(value = "浪屿收费价格")
    private Double price;

    @ApiModelProperty(value = "浪屿类型（0记忆、1帖子、2卡片）")
    @JsonValue
    private IslandTypeEnum type;

    @TableLogic
    private Integer isDeleted;

    @TableField(fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;



    public static List<IslandListVO> DOListToVOList(List<IslandDO> islandDOList) {
        List<IslandListVO> islandListVOS = new ArrayList<>();
        for (IslandDO islandDO : islandDOList) {
            IslandListVO islandListVO = new IslandListVO();
            BeanUtils.copyProperties(islandDO,islandListVO);
            islandListVO.setType(islandDO.getType().getType());
            islandListVOS.add(islandListVO);
        }
        return islandListVOS;
    }

    public static List<IslandListVO> DOListToVOList(List<IslandDO> islandDOList, Map<String, IslandUserListVO> map) {
        List<IslandListVO> islandListVOS = new ArrayList<>();
        for (IslandDO islandDO : islandDOList) {
            IslandListVO islandListVO = new IslandListVO();
            BeanUtils.copyProperties(islandDO,islandListVO);
            islandListVO.setType(islandDO.getType().getType());
            IslandUserListVO islandUserListVO = map.get(islandDO.getId());
            if(islandUserListVO != null){
                islandListVO.setJoined(true);
                islandListVO.setRole(islandUserListVO.getRole());
                islandListVO.setIsFixed(islandUserListVO.getIsFixed());
            }
            islandListVOS.add(islandListVO);
        }
        return islandListVOS;
    }
}
